package com.xyzm.mongo_demo.dao;

import com.xyzm.mongo_demo.entiry.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StudentDao {
    @Autowired
    MongoTemplate mongoTemplate;

    public Student query(Query query){
        Student one = mongoTemplate.findOne(query, Student.class);
        return one;
    }
    public List findAll(){
        List<Student> all = mongoTemplate.findAll(Student.class);
        return all;
    }
    public Student insert(Student t){
        Student insert = mongoTemplate.insert(t);
        return insert;
    }
    public void update(Query query, Update update){
        mongoTemplate.updateMulti(query,update,Student.class);
    }
}
